/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_RTICONNEXTDDS_DATAREADER_LISTENER_IMPL_HPP_
#define _DAL_RTICONNEXTDDS_DATAREADER_LISTENER_IMPL_HPP_

#include "ndds/ndds_c.h"
#include "dal/topic.h"
#include "dal/subscriber.h"
#include "dal_rticonnextdds/utils/ReferenceCount.hpp"
#include "dal_rticonnextdds/converter/StatusConverter.hpp"

typedef struct DDS_DataReaderListener DDS_DataReaderListener;

class DataReaderListenerImpl
{
public:
    DataReaderListenerImpl(dal_datareader_listener_callbacks_t callbacks);
    ~DataReaderListenerImpl();

    ReferenceCount ref_count_;

    DDS_DataReaderListener* getListener();

    static void on_requested_deadline_missed(void* listener_data,
                                             DDS_DataReader* reader,
                                             const DDS_RequestedDeadlineMissedStatus* status);

    static void on_requested_incompatible_qos(void* listener_data,
                                              DDS_DataReader* reader,
                                              const DDS_RequestedIncompatibleQosStatus* status);

    static void on_sample_rejected(void* listener_data,
                                   DDS_DataReader* reader,
                                   const DDS_SampleRejectedStatus* status);

    static void on_liveliness_changed(void* listener_data,
                                      DDS_DataReader* reader,
                                      const DDS_LivelinessChangedStatus* status);

    static void
    on_sample_lost(void* listener_data, DDS_DataReader* reader, const DDS_SampleLostStatus* status);

    static void on_subscription_matched(void* listener_data,
                                        DDS_DataReader* reader,
                                        const DDS_SubscriptionMatchedStatus* status);

    static void on_data_available(void* listener_data, DDS_DataReader* reader);

    static void on_requested_deadline_missed_dummy(void* listener_data,
                                                   DDS_DataReader* reader,
                                                   const DDS_RequestedDeadlineMissedStatus* status);

    static void
    on_requested_incompatible_qos_dummy(void* listener_data,
                                        DDS_DataReader* reader,
                                        const DDS_RequestedIncompatibleQosStatus* status);

    static void on_sample_rejected_dummy(void* listener_data,
                                         DDS_DataReader* reader,
                                         const DDS_SampleRejectedStatus* status);

    static void on_liveliness_changed_dummy(void* listener_data,
                                            DDS_DataReader* reader,
                                            const DDS_LivelinessChangedStatus* status);

    static void on_sample_lost_dummy(void* listener_data,
                                     DDS_DataReader* reader,
                                     const DDS_SampleLostStatus* status);

    static void on_subscription_matched_dummy(void* listener_data,
                                              DDS_DataReader* reader,
                                              const DDS_SubscriptionMatchedStatus* status);

    static void on_data_available_dummy(void* listener_data, DDS_DataReader* reader);

private:
    dal_datareader_listener_callbacks_t callbacks_;
    DDS_DataReaderListener* rti_reader_listener_ = nullptr;
};

#endif  // _DAL_RTICONNEXTDDS_DATAREADER_LISTENER_IMPL_HPP_